""" & Accuracy & Precision & Recall & F1-score 
MaMaDroid~\cite{onwuzurike2019mamadroid} & 97.24 & 96.69 & 97.86 & 97.27
Drebin~\cite{arp2014drebin}             & 97.77 & 97.79 & 97.77 & 97.78
DetectBERT~\cite{sun2024detectbert}     & 94.64 & 94.71 & 94.19 & 94.45 
MsDroid~\cite{he2022msdroid}          & 96.03 & 96.09 & 96.18 & 96.14 
\textbf{CansDroid (Ours)}               & \textbf{99.38} & \textbf{99.40} & \textbf{99.43} & \textbf{99.42} & 
 """

import matplotlib.pyplot as plt
import numpy as np
import matplotlib
from matplotlib import rcParams

# Set publication-quality parameters
rcParams['font.family'] = 'serif'
rcParams['font.serif'] = ['Times New Roman', 'DejaVu Serif']
rcParams['font.size'] = 12
rcParams['axes.linewidth'] = 1.2
rcParams['axes.spines.top'] = False
rcParams['axes.spines.right'] = False
rcParams['xtick.major.size'] = 6
rcParams['xtick.minor.size'] = 3
rcParams['ytick.major.size'] = 6
rcParams['ytick.minor.size'] = 3
rcParams['legend.frameon'] = False
rcParams['figure.dpi'] = 300

# Data
methods = ['CansDroid\n(Ours)', 'MaMaDroid', 'Drebin', 'DetectBERT', 'MsDroid']
accuracy = [98.61, 90.79, 97.21, 92.03, 95.75]
precision = [98.85, 91.38, 97.22, 92.05, 94.34]
recall = [98.56, 90.79, 97.21, 92.03 , 93.80]
f1_score = [98.70, 91.08 , 97.22 , 92.04 , 94.07]

# Professional color scheme (grayscale-friendly)
# colors = ['#2E3440', '#3B4252', '#434C5E', '#5E81AC']
colors = ['#7891b5', '#aeb9cb', '#e5e5ea', '#efe1e0']
patterns = ['', '', '', '']

# Set figure parameters for side-by-side layout (0.5\linewidth each)
fig, ax = plt.subplots(figsize=(4, 4))
x = np.arange(len(methods)) * 1.5  # Increase spacing between method groups
width = 0.165

# Create bars with professional styling
rects1 = ax.bar(x - 1.5*width, accuracy, width, label='Accuracy', 
                color=colors[0], edgecolor='black', linewidth=0.8, 
                hatch=patterns[0], alpha=0.9)
rects2 = ax.bar(x - 0.5*width, precision, width, label='Precision', 
                color=colors[1], edgecolor='black', linewidth=0.8, 
                hatch=patterns[1], alpha=0.9)
rects3 = ax.bar(x + 0.5*width, recall, width, label='Recall', 
                color=colors[2], edgecolor='black', linewidth=0.8, 
                hatch=patterns[2], alpha=0.9)
rects4 = ax.bar(x + 1.5*width, f1_score, width, label='F1-Score', 
                color=colors[3], edgecolor='black', linewidth=0.8, 
                hatch=patterns[3], alpha=0.9)

# Set labels and formatting
ax.set_xlabel('Methods', fontsize=14, fontweight='bold')
ax.set_ylabel('Performance (%)', fontsize=14, fontweight='bold')
ax.set_xticks(x)
ax.set_xticklabels(methods, fontsize=1)
ax.tick_params(axis='both', which='major', labelsize=9)

# Set y-axis range and ticks
ax.set_ylim(90, 99.5)
ax.set_yticks(np.arange(90,99.5, 1))

# Add subtle grid
ax.grid(True, alpha=0.3, axis='y', linestyle='-', linewidth=0.5)
ax.set_axisbelow(True)

# Professional legend
legend = ax.legend(loc='upper right', fontsize=11, ncol=2, 
                  columnspacing=1.5, handlelength=2)
legend.get_frame().set_alpha(0.9)

# Add value labels on bars
def add_value_labels(rects, offset=0.1):
    for rect in rects:
        height = rect.get_height()
        ax.annotate(f'{height:.1f}',
                    xy=(rect.get_x() + rect.get_width() / 2, height + offset),
                    ha='center', va='bottom',
                    fontsize=8, fontweight='normal', rotation=0)

# Add value labels only for the highest metric of each method
def add_value_labels_selective():
    all_rects = [rects1, rects2, rects3, rects4]
    all_data = [accuracy, precision, recall, f1_score]
    
    for i in range(len(methods)):
        # Find the highest value and its index for this method
        method_values = [data[i] for data in all_data]
        max_value = max(method_values)
        max_index = method_values.index(max_value)
        
        # Only add label to the highest bar
        rect = all_rects[max_index][i]
        height = rect.get_height()
        ax.annotate(f'{height:.2f}',
                    xy=(rect.get_x() + rect.get_width() / 2, height + 0.1),
                    ha='center', va='bottom',
                    fontsize=9, fontweight='bold', rotation=0)

add_value_labels_selective()

# Remove highlight for cleaner appearance

# Adjust layout
plt.tight_layout()

# Save with publication quality
plt.savefig('malware_class_performance.pdf', dpi=300, bbox_inches='tight', 
            format='pdf', facecolor='white', edgecolor='none')
plt.savefig('malware_class_performance.png', dpi=300, bbox_inches='tight', 
            format='png', facecolor='white', edgecolor='none')
plt.savefig('malware_class_performance.eps', dpi=300, bbox_inches='tight', 
            format='eps', facecolor='white', edgecolor='none')

# Display the plot
plt.show()

print("Publication-quality charts generated:")
print("- malware_detection_performance.pdf (vector format for LaTeX)")
print("- malware_detection_performance.png (high-resolution raster)")
print("- malware_detection_performance.eps (vector format for some journals)")

 